import { createStore } from 'redux';

const reducer = (
  preState = { showBar: true, cityName: '北京', cityId: 110100 },
  action = {}
) => {
  console.log('preState', preState);
  console.log('preState', action);
  const state = { ...preState };
  const { type, payload } = action;
  switch (type) {
    case 'hide-tabbar':
      state.showBar = false;
      return state;
    case 'show-tabbar':
      state.showBar = true;
      return state;
    case 'change-city':
      const { cityId, cityName } = payload;
      state.cityId = cityId;
      state.cityName = cityName;
      return state;
    default:
      return preState;
  }
};

const store = createStore(reducer);

export default store;
